<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Js</title>
    <style>
        #out{
            width: 1000px;
            height: 40px;
            border: 1px solid #333;
        }
        #in{
            width: 0%;
            height: 40px;
            background-color: #05f;
            text-align: center;
            line-height: 40px;
            color:#fff;
            font-size: 25px;
        }
        button{
            width: 200px;
            height: 50px;
            font-size: 30px;
            background-color : #fff;
            color : #000;
        }
    </style>
</head>
<body>

    <h1>下载进度条</h1>
    <hr>
    <button id="btn" onclick="s()">开始</button>
    <br><br><br><br>
    <div id="out">
        <div id="in"></div>
    </div>

    <script>
        //获取div 和 btn
        var div = document.getElementById('in');
        var btn = document.getElementById('btn');

        var m = 0;//下载进度
        var mark = true;//暂停标记

        function run(){
            //判断定时结束
            if (m == 100) {
                btn.innerHTML = '已下载完成';
                alert('迅雷提示 : 您的小片儿 已经下载好了!');
                clearInterval(timer);
                m = 0;
                return;
            }
            m++;
            div.style.width = m+'%';
            div.innerHTML = m+' '+'%';
        }

        //设置定时操作函数
        function s(){
            if (m > 0) {
                //根据标记判断是否暂停
                if (mark) {
                    mark = false;//改标记状态
                    clearInterval(timer);
                    btn.innerHTML = '开始';
                    btn.style.color = '#000';
                    btn.style.backgroundColor = '#fff';
                }else{
                    mark = true;//改标记状态
                    timer = setInterval(run,100);
                    btn.innerHTML = '暂停';
                    btn.style.color = '#fff';
                    btn.style.backgroundColor = '#000';
                }
            }else{
                //首次开始,即m=0时
                timer = setInterval(run,100);
                btn.innerHTML = '暂停';
                btn.style.color = '#fff';
                btn.style.backgroundColor = '#000';
            }
        }

    </script>
</body>
</html>